
  ___  ____  ____  ____  ____ ©
 /__    /   ____/   /   ____/      17.0
___/   /   /___/   /   /___/       MP—Parallel Edition

 Statistics and Data Science       Copyright 1985-2021 StataCorp LLC
                                   StataCorp
                                   4905 Lakeway Drive
                                   College Station, Texas 77845 USA
                                   800-STATA-PC        https://www.stata.com
                                   979-696-4600        stata@stata.com

Stata license: Unlimited-user 4-core network, expiring  8 Oct 2022
Serial number: 501709301797
  Licensed to: Florian Peters
               University of Amsterdam

Notes:
      1. Stata is running in batch mode.
      2. Unicode is supported; see help unicode_advice.
      3. More than 2 billion observations are allowed; see help obs_advice.
      4. Maximum number of variables is set to 5,000; see help set_maxvar.

. do run_all.do 

. do reduced_form.do

. clear

. discard

. set more off

. 
. adopath ++ "./ado/"
  [1]              "./ado/"
  [2]  (BASE)      "/Applications/Stata/ado/base/"
  [3]  (SITE)      "/Applications/Stata/ado/site/"
  [4]              "."
  [5]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [6]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [7]  (OLDPLACE)  "~/ado/"

. 
. ******************
. *** Parameters ***
. ******************
. 
. local file_name_consensus "./input/consensus_dataset.csv"  // Data file

. local file_name_individual "./input/individual_dataset.csv" // Data file

. local output_folder "./output/reduced_form" // Output directory

. local alpha = 0.05 // Significance level

. local L_NW = 5 // Number of lags for calculating Newey-West standard errors

. 
. *****************************
. *** Import CONSENSUS data ***
. *****************************
. 
. import delimited using `file_name_consensus', case(preserve)
(encoding automatically selected: ISO-8859-1)
(10 vars, 215 obs)

. rename DATE Date

. 
. gen qtr = quarterly(Date,"YQ")

. format qtr %tq

. tsset qtr // Set to time series

Time variable: qtr, 1968q4 to 2022q2
        Delta: 1 quarter

. 
. **************************
. *** Generate variables ***
. **************************
. 
. gen Efor_Step2 = Realiz1 - SPFfor_Step2
(5 missing values generated)

. gen Rfor_Step2 = SPFfor_Step2 - SPFfor_Step3
(5 missing values generated)

. gen L1_Efor_Step2 = l1.Efor_Step2
(5 missing values generated)

. gen L1_Realiz1 = l1.Realiz1
(4 missing values generated)

. 
. *******************
. *** Regressions ***
. *******************
. 
. * Clean up
. shell rm -r `output_folder'

rm: ./output/reduced_form: No such file or directory

. shell mkdir -p ./output


. shell mkdir `output_folder'


. 
. * Ensure common sample
. drop if (missing(Efor_Step2) | missing(Rfor_Step2) | missing(L1_Efor_Step2) | missing(L1_Realiz1))
(6 observations deleted)

. 
. * Regressions
. newey Efor_Step2 Rfor_Step2, lag(`L_NW')

Regression with Newey–West standard errors      Number of obs     =        209
Maximum lag = 5                                 F(  1,       207) =       0.99
                                                Prob > F          =     0.3199

------------------------------------------------------------------------------
             |             Newey–West
  Efor_Step2 | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
  Rfor_Step2 |    .402739   .4039238     1.00   0.320    -.3935929    1.199071
       _cons |  -.0241376   .1454494    -0.17   0.868    -.3108897    .2626145
------------------------------------------------------------------------------

. matrix CG_coefs_cons = e(b)

. matrix CG_cov_cons = e(V)

. 
. newey Efor_Step2 L1_Efor_Step2, lag(`L_NW')

Regression with Newey–West standard errors      Number of obs     =        209
Maximum lag = 5                                 F(  1,       207) =      12.24
                                                Prob > F          =     0.0006

-------------------------------------------------------------------------------
              |             Newey–West
   Efor_Step2 | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
--------------+----------------------------------------------------------------
L1_Efor_Step2 |   .3748799    .107157     3.50   0.001      .163621    .5861388
        _cons |  -.0166115   .1043927    -0.16   0.874    -.2224207    .1891977
-------------------------------------------------------------------------------

. matrix autocorr_coefs_cons = e(b)

. matrix autocorr_cov_cons = e(V)

. 
. newey Efor_Step2 L1_Realiz1, lag(`L_NW')

Regression with Newey–West standard errors      Number of obs     =        209
Maximum lag = 5                                 F(  1,       207) =       2.08
                                                Prob > F          =     0.1510

------------------------------------------------------------------------------
             |             Newey–West
  Efor_Step2 | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
  L1_Realiz1 |   .1102087   .0764686     1.44   0.151    -.0405485    .2609659
       _cons |  -.4042678   .1932652    -2.09   0.038    -.7852883   -.0232474
------------------------------------------------------------------------------

. matrix extrap_coefs_cons = e(b)

. matrix extrap_cov_cons = e(V)

. 
. * Save output
. mat2txt, matrix(CG_coefs_cons) saving(`output_folder'/ex_CG_coefs_consensus.txt)

. mat2txt, matrix(CG_cov_cons) saving(`output_folder'/ex_CG_cov_consensus.txt)

. matrix N_cons = e(N)

. 
. mat2txt, matrix(autocorr_coefs_cons) saving(`output_folder'/ex_autocorr_coefs_consensus.txt)

. mat2txt, matrix(autocorr_cov_cons) saving(`output_folder'/ex_autocorr_cov_consensus.txt)

. 
. mat2txt, matrix(extrap_coefs_cons) saving(`output_folder'/ex_extrap_coefs_consensus.txt)

. mat2txt, matrix(extrap_cov_cons) saving(`output_folder'/ex_extrap_cov_consensus.txt)

. 
. mat2txt, matrix(N_cons) saving(`output_folder'/N_cons.txt)

. 
. clear

. 
. ******************************
. *** Import INDIVIDUAL data ***
. ******************************
. 
. import delimited using `file_name_individual', case(preserve)
(encoding automatically selected: ISO-8859-1)
(10 vars, 71,810 obs)

. 
. gen qtr = quarterly(DATE,"YQ")

. format qtr %tq

. xtset ID qtr // Set to panel data

Panel variable: ID (strongly balanced)
 Time variable: qtr, 1968q4 to 2022q2
         Delta: 1 quarter

. 
. **************************
. *** Generate variables ***
. **************************
. 
. gen Efor_Step2 = Realiz1 - SPFfor_Step2
(63,826 missing values generated)

. gen Rfor_Step2 = SPFfor_Step2 - SPFfor_Step3
(65,720 missing values generated)

. gen L1_Efor_Step2 = l1.Efor_Step2
(63,826 missing values generated)

. gen L1_Realiz1 = l1.Realiz1
(59,829 missing values generated)

. 
. *******************
. *** Regressions ***
. *******************
. 
. * Ensure common sample
. drop if (missing(Efor_Step2) | missing(Rfor_Step2) | missing(L1_Efor_Step2) | missing(L1_Realiz1))
(65,753 observations deleted)

. 
. * Regressions
. reghdfe Efor_Step2 Rfor_Step2, absorb(ID) vce(cluster ID DATE)
(dropped 27 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      6,030
Absorbing 1 HDFE group                            F(   1,    208) =      79.79
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.2131
                                                  Adj R-squared   =     0.1780
Number of clusters (ID)      =        258         Within R-sq.    =     0.0911
Number of clusters (DATE)    =        209         Root MSE        =     1.6778

                              (Std. err. adjusted for 209 clusters in ID DATE)
------------------------------------------------------------------------------
             |               Robust
  Efor_Step2 | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
  Rfor_Step2 |  -.3814679   .0427056    -8.93   0.000    -.4656592   -.2972766
       _cons |   .0042816   .0975459     0.04   0.965    -.1880237    .1965869
------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          ID |       258         258           0    *|
-----------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. matrix CG_coefs_micro = e(b)

. matrix CG_cov_micro = e(V)

. matrix N_micro = e(N)

. 
. reghdfe Efor_Step2 L1_Efor_Step2, absorb(ID) vce(cluster ID DATE)
(dropped 27 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      6,030
Absorbing 1 HDFE group                            F(   1,    208) =      12.14
Statistics robust to heteroskedasticity           Prob > F        =     0.0006
                                                  R-squared       =     0.1805
                                                  Adj R-squared   =     0.1438
Number of clusters (ID)      =        258         Within R-sq.    =     0.0534
Number of clusters (DATE)    =        209         Root MSE        =     1.7123

                               (Std. err. adjusted for 209 clusters in ID DATE)
-------------------------------------------------------------------------------
              |               Robust
   Efor_Step2 | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
--------------+----------------------------------------------------------------
L1_Efor_Step2 |    .228156   .0654739     3.48   0.001     .0990785    .3572335
        _cons |   .0043574   .0926475     0.05   0.963    -.1782911    .1870058
-------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          ID |       258         258           0    *|
-----------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. matrix autocorr_coefs_micro = e(b)

. matrix autocorr_cov_micro = e(V)

. 
. reghdfe Efor_Step2 L1_Realiz1, absorb(ID) vce(cluster ID DATE)
(dropped 27 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      6,030
Absorbing 1 HDFE group                            F(   1,    208) =       1.79
Statistics robust to heteroskedasticity           Prob > F        =     0.1824
                                                  R-squared       =     0.1458
                                                  Adj R-squared   =     0.1076
Number of clusters (ID)      =        258         Within R-sq.    =     0.0133
Number of clusters (DATE)    =        209         Root MSE        =     1.7481

                              (Std. err. adjusted for 209 clusters in ID DATE)
------------------------------------------------------------------------------
             |               Robust
  Efor_Step2 | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
  L1_Realiz1 |   .1189723   .0889354     1.34   0.182     -.056358    .2943026
       _cons |  -.3807463   .2844863    -1.34   0.182    -.9415924    .1800998
------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          ID |       258         258           0    *|
-----------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. matrix extrap_coefs_micro = e(b)

. matrix extrap_cov_micro = e(V)

. 
. 
. * Save output
. mat2txt, matrix(CG_coefs_micro) saving(`output_folder'/ex_CG_coefs_micro.txt)

. mat2txt, matrix(CG_cov_micro) saving(`output_folder'/ex_CG_cov_micro.txt)

. 
. mat2txt, matrix(autocorr_coefs_micro) saving(`output_folder'/ex_autocorr_coefs_micro.txt)

. mat2txt, matrix(autocorr_cov_micro) saving(`output_folder'/ex_autocorr_cov_micro.txt)

. 
. mat2txt, matrix(extrap_coefs_micro) saving(`output_folder'/ex_extrap_coefs_micro.txt)

. mat2txt, matrix(extrap_cov_micro) saving(`output_folder'/ex_extrap_cov_micro.txt)

. 
. mat2txt, matrix(N_micro) saving(`output_folder'/N_micro.txt)

. 
. 
. 
end of do-file

. do consensus.do

. clear

. discard

. set more off

. 
. adopath ++ "./ado/"
  [1]              "./ado/"
  [2]  (BASE)      "/Applications/Stata/ado/base/"
  [3]  (SITE)      "/Applications/Stata/ado/site/"
  [4]              "."
  [5]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [6]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [7]  (OLDPLACE)  "~/ado/"

. 
. ******************
. *** Parameters ***
. ******************
. 
. local file_name "./input/consensus_dataset.csv"  // Data file

. local output_folder "./output/consensus" // Output directory

. local K = 4 // Number of lags to include when calculating local projections

. local L = 16 // Number of IRF coefficients to estimate

. local alpha = 0.05 // Significance level

. local L_NW = 5 // Number of lags for calculating Newey-West standard errors

. 
. *************************************
. *** Import data and set data type ***
. *************************************
. 
. import delimited using `file_name', case(preserve)
(encoding automatically selected: ISO-8859-1)
(10 vars, 215 obs)

. rename DATE Date

. 
. gen qtr = quarterly(Date,"YQ")

. format qtr %tq

. tsset qtr // Set to time series

Time variable: qtr, 1968q4 to 2022q2
        Delta: 1 quarter

. 
. ********************************
. *** Generate forecast errors ***
. ********************************
. 
. gen Efor_Step2 = Realiz1 - SPFfor_Step2
(5 missing values generated)

. 
. ***********************************
. *** Calculate local projections ***
. ***********************************
. 
. estimate_IRF_LP Realiz1, k(`K') l(`L') alpha(`alpha') min_lags_NW(`L_NW') 

. matrix IRF_actual = e(s)

. 
. estimate_IRF_LP Efor_Step2, k(`K') l(`L') alpha(`alpha') min_lags_NW(`L_NW') 

. matrix IRF_LP_1Q_ahead = e(s)

. 
. estimate_IRF_ML Efor_Step2, l(`L') alpha(`alpha')

. matrix IRF_MA_1Q_ahead = e(s)

. 
. * Estimate a simple AR(4) for forecast errors
. quietly newey Efor_Step2 l1.Efor_Step2 l2.Efor_Step2 l3.Efor_Step2 l4.Efor_Step2, lag(`K')

. matrix AR_coefs = e(b)

. matrix AR_coefs_cov = e(V)

. 
. ******************
. *** Get graphs ***
. ******************
. 
. * Clean up
. shell rm -r `output_folder'

rm: ./output/consensus: No such file or directory

. shell mkdir -p ./output


. shell mkdir `output_folder'


. 
. * Get plots
. plot_IRF "IRF_actual" `output_folder' "IRF_actual"
file /Users/fpeters/Dropbox/KP/REStat/accept/submission_files/measuring_expectations/code/stata/output/consensus/IRF_actual.pdf saved as PDF
    format

. plot_IRF "IRF_LP_1Q_ahead" `output_folder' "IRF_LP_1Q_ahead"
file /Users/fpeters/Dropbox/KP/REStat/accept/submission_files/measuring_expectations/code/stata/output/consensus/IRF_LP_1Q_ahead.pdf saved as PDF
    format

. plot_IRF "IRF_MA_1Q_ahead" `output_folder' "IRF_MA_1Q_ahead"
file /Users/fpeters/Dropbox/KP/REStat/accept/submission_files/measuring_expectations/code/stata/output/consensus/IRF_MA_1Q_ahead.pdf saved as PDF
    format

. 
. * Save estimated IRFs
. mat2txt, matrix(IRF_actual) saving(`output_folder'/IRF_actual.txt)

. mat2txt, matrix(IRF_LP_1Q_ahead) saving(`output_folder'/IRF_LP_1Q_ahead.txt)

. mat2txt, matrix(IRF_MA_1Q_ahead) saving(`output_folder'/IRF_MA_1Q_ahead.txt)

. mat2txt, matrix(AR_coefs) saving(`output_folder'/AR_coefs_1Q_ahead.txt)

. mat2txt, matrix(AR_coefs_cov) saving(`output_folder'/AR_coefs_cov_1Q_ahead.txt)

. 
. * Get summary statistics
. summary_stats_forecasts Efor_Step2 Realiz1, k(`K')

. matrix stats_Step2 = e(s)

. mat2txt, matrix(stats_Step2) saving(`output_folder'/stats_1Q_ahead.txt)

. 
end of do-file

. do individual.do

. clear

. discard

. set more off

. 
. adopath ++ "./ado/"
  [1]              "./ado/"
  [2]  (BASE)      "/Applications/Stata/ado/base/"
  [3]  (SITE)      "/Applications/Stata/ado/site/"
  [4]              "."
  [5]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [6]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [7]  (OLDPLACE)  "~/ado/"

. adopath ++ "../tools/"
  [1]              "../tools/"
  [2]              "./ado/"
  [3]  (BASE)      "/Applications/Stata/ado/base/"
  [4]  (SITE)      "/Applications/Stata/ado/site/"
  [5]              "."
  [6]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [7]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [8]  (OLDPLACE)  "~/ado/"

. adopath ++ "../ssc/"
  [1]              "../ssc/"
  [2]              "../tools/"
  [3]              "./ado/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. 
. ******************
. *** Parameters ***
. ******************
. 
. local file_name "./input/individual_dataset.csv" // Data file

. local output_folder "./output/individual" // Output directory

. local K = 4 // Number of lags to include when calculating local projections

. local L = 16 // Number of IRF coefficients to estimate

. local alpha = 0.05 // Significance level

. 
. *************************************
. *** Import data and set data type ***
. *************************************
. 
. import delimited using `file_name', case(preserve)
(encoding automatically selected: ISO-8859-1)
(10 vars, 71,810 obs)

. 
. gen qtr = quarterly(DATE,"YQ")

. format qtr %tq

. xtset ID qtr // Set to panel data

Panel variable: ID (strongly balanced)
 Time variable: qtr, 1968q4 to 2022q2
         Delta: 1 quarter

. 
. **************************
. *** Generate variables ***
. **************************
. 
. * Forecast errors
. gen Efor_Step2 = Realiz1 - SPFfor_Step2
(63,826 missing values generated)

. 
. * Generate winsorized variable
. winsor2 Efor_Step2, suffix(_w) cuts(5 95)

. 
. ***********************************
. *** Calculate local projections ***
. ***********************************
. 
. * Main regression
. estimate_IRF_LP Efor_Step2, l(`L') k(`K') alpha(`alpha') ///
>         method("fe") fe_var("ID") cluster_var("ID") cluster_var_two_way("qtr") 

. matrix IRF = e(s)

. 
. * Winsorized regression
. estimate_IRF_LP Efor_Step2_w, l(`L') k(`K') alpha(`alpha') ///
>         method("fe") fe_var("ID") cluster_var("ID") cluster_var_two_way("qtr") 

. matrix IRF_w = e(s)

. 
. * Estimate a simple AR(4) for forecast errors
. quietly reghdfe Efor_Step2 l1.Efor_Step2 l2.Efor_Step2 l3.Efor_Step2 l4.Efor_Step2, ///
>         absorb(ID) vce(cluster ID qtr)

. matrix AR_coefs = e(b)

. matrix AR_coefs_cov = e(V)

. 
. ******************
. *** Get graphs ***
. ******************
. 
. * Clean up
. shell rm -r `output_folder'

rm: ./output/individual: No such file or directory

. shell mkdir -p ./output


. shell mkdir `output_folder'


. 
. * Get plots
. plot_IRF "IRF" `output_folder' "IRF"
file /Users/fpeters/Dropbox/KP/REStat/accept/submission_files/measuring_expectations/code/stata/output/individual/IRF.pdf saved as PDF format

. 
. * Save estimated IRFs
. mat2txt, matrix(IRF) saving(`output_folder'/IRF_LP_1Q_ahead.txt)

. mat2txt, matrix(IRF_w) saving(`output_folder'/IRF_LP_1Q_ahead_winsorized.txt)

. mat2txt, matrix(AR_coefs) saving(`output_folder'/AR_coefs_1Q_ahead.txt)

. mat2txt, matrix(AR_coefs_cov) saving(`output_folder'/AR_coefs_cov_1Q_ahead.txt)

. 
. * Get summary statistics
. summary_stats_forecasts Efor_Step2 Realiz1, k(`K')

. matrix stats_Step2 = e(s)

. mat2txt, matrix(stats_Step2) saving(`output_folder'/stats_1Q_ahead.txt)

. 
end of do-file

. do idiosyncratic.do

. clear

. discard

. set more off

. 
. adopath ++ "./ado/"
  [1]              "./ado/"
  [2]              "../ssc/"
  [3]              "../tools/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. adopath ++ "../tools/"
  [1]              "../tools/"
  [2]              "./ado/"
  [3]              "../ssc/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. adopath ++ "../ssc/"
  [1]              "../ssc/"
  [2]              "../tools/"
  [3]              "./ado/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. 
. ******************
. *** Parameters ***
. ******************
. 
. local file_name "./input/individual_dataset.csv" // Data file

. local output_folder "./output/idiosyncratic" // Output directory

. local K = 4 // Number of lags to include when calculating local projections

. local L = 16 // Number of IRF coefficients to estimate

. local alpha = 0.05 // Significance level

. 
. *************************************
. *** Import data and set data type ***
. *************************************
. 
. import delimited using `file_name', case(preserve)
(encoding automatically selected: ISO-8859-1)
(10 vars, 71,810 obs)

. 
. gen qtr = quarterly(DATE,"YQ")

. 
. **************************
. *** Generate variables ***
. **************************
. 
. * Forecast errors
. gen Efor_Step2 = Realiz1 - SPFfor_Step2
(63,826 missing values generated)

. 
. * Deviations from consensus
. bysort DATE: egen Consensusfor_Step2 = mean(SPFfor_Step2)
(1,336 missing values generated)

. gen DevFromConsensusfor_Step2 = SPFfor_Step2 - Consensusfor_Step2
(63,791 missing values generated)

. 
. * Set to panel data
. xtset ID qtr

Panel variable: ID (strongly balanced)
 Time variable: qtr, 35 to 249
         Delta: 1 unit

. 
. * Generate winsorized variables
. winsor2 Efor_Step2 DevFromConsensusfor_Step2 SPFfor_Step2, suffix(_w) cuts(5 95)

. 
. ***********************************
. *** Calculate local projections ***
. ***********************************
. 
. * Estimate a simple AR(4) for deviations from consensus
. reghdfe DevFromConsensusfor_Step2 l1.DevFromConsensusfor_Step2 l2.DevFromConsensusfor_Step2 l3.DevFromConsensusfor_Step2 l4.DevFromConsensusfor_St
> ep2, /// 
>                 absorb(ID) cluster(ID qtr)
(dropped 15 singleton observations)
(MWFE estimator converged in 1 iterations)
Warning: VCV matrix was non-positive semi-definite; adjustment from Cameron, Gelbach & Miller applied.

HDFE Linear regression                            Number of obs   =      3,509
Absorbing 1 HDFE group                            F(   4,    185) =       4.50
Statistics robust to heteroskedasticity           Prob > F        =     0.0017
                                                  R-squared       =     0.2009
                                                  Adj R-squared   =     0.1554
Number of clusters (ID)      =        186         Within R-sq.    =     0.0285
Number of clusters (qtr)     =        207         Root MSE        =     0.9317

                                            (Std. err. adjusted for 186 clusters in ID qtr)
-------------------------------------------------------------------------------------------
                          |               Robust
DevFromConsensusfor_Step2 | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
--------------------------+----------------------------------------------------------------
DevFromConsensusfor_Step2 |
                      L1. |   .1439111   .0401914     3.58   0.000     .0646187    .2232036
                      L2. |  -.0183736   .0368201    -0.50   0.618    -.0910148    .0542675
                      L3. |   .0233535   .0280567     0.83   0.406    -.0319986    .0787057
                      L4. |    .068889   .0350333     1.97   0.051    -.0002272    .1380052
                          |
                    _cons |  -.0192306   .0027723    -6.94   0.000       -.0247   -.0137612
-------------------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          ID |       186         186           0    *|
-----------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. matrix AR_coefs = e(b)

. matrix AR_coefs_cov = e(V)

. 
. * Estimate with deviations from consensus as IV
. matrix res_baseline = J(`L', 8, .)

. matrix colnames res_baseline = lag IRF se lb ub df_resid K F_stat

.         
. forvalues ii = 1/`L' {
  2.         local ii_1 = `ii' - 1
  3.         quietly ivreghdfe f`ii_1'.Efor_Step2 l1.DevFromConsensusfor_Step2 l2.DevFromConsensusfor_Step2 l3.DevFromConsensusfor_Step2 l4.DevFromC
> onsensusfor_Step2 /// 
>                 (SPFfor_Step2 = DevFromConsensusfor_Step2), /// 
>                 absorb(ID) cluster(ID qtr)
  4.                 
.         * Collect the results and calculate 
.         * confidence intervals at the given significance level
.         local se = _se[SPFfor_Step2]
  5.         local df_r = e(df_r) 
  6.         local t_crit = invt(`df_r', `alpha' / 2)
  7.         
.         matrix res_baseline [`ii', 1] = `ii'
  8.         matrix res_baseline [`ii', 2] = _b[SPFfor_Step2]
  9.         matrix res_baseline [`ii', 3] = `se'
 10.         matrix res_baseline [`ii', 4] = _b[SPFfor_Step2] + ///
>                 `t_crit' * `se'
 11.         matrix res_baseline [`ii', 5] = _b[SPFfor_Step2] - ///
>                 `t_crit' * `se'
 12.         matrix res_baseline [`ii', 6] = `df_r'
 13.         matrix res_baseline [`ii', 7] = `K'
 14.         matrix res_baseline [`ii', 8] = e(widstat)
 15. }       
Warning: estimated covariance matrix of moment conditions not of full rank.
         overidentification statistic not reported, and standard errors and
         model tests should be interpreted with caution.
Possible causes:
         number of clusters insufficient to calculate robust covariance matrix
         singleton dummy variable (dummy with one 1 and N-1 0s or vice versa)
partial option may address problem.
Warning: estimated covariance matrix of moment conditions not of full rank.
         overidentification statistic not reported, and standard errors and
         model tests should be interpreted with caution.
Possible causes:
         number of clusters insufficient to calculate robust covariance matrix
         singleton dummy variable (dummy with one 1 and N-1 0s or vice versa)
partial option may address problem.

. 
. * Estimate with deviations from consensus as IV -- winsorized
. matrix res_winsorized = J(`L', 8, .)

. matrix colnames res_winsorized = lag IRF se lb ub df_resid K F_stat

.         
. forvalues ii = 1/`L' {
  2.         local ii_1 = `ii' - 1
  3.         quietly ivreghdfe f`ii_1'.Efor_Step2_w l1.DevFromConsensusfor_Step2_w l2.DevFromConsensusfor_Step2_w l3.DevFromConsensusfor_Step2_w l4.
> DevFromConsensusfor_Step2_w /// 
>                 (SPFfor_Step2_w = DevFromConsensusfor_Step2_w), /// 
>                 absorb(ID) cluster(ID qtr)
  4.                 
.         * Collect the results and calculate 
.         * confidence intervals at the given significance level
.         local se = _se[SPFfor_Step2_w]
  5.         local df_r = e(df_r) 
  6.         local t_crit = invt(`df_r', `alpha' / 2)
  7.         
.         matrix res_winsorized [`ii', 1] = `ii'
  8.         matrix res_winsorized [`ii', 2] = _b[SPFfor_Step2_w]
  9.         matrix res_winsorized [`ii', 3] = `se'
 10.         matrix res_winsorized [`ii', 4] = _b[SPFfor_Step2_w] + ///
>                 `t_crit' * `se'
 11.         matrix res_winsorized [`ii', 5] = _b[SPFfor_Step2_w] - ///
>                 `t_crit' * `se'
 12.         matrix res_winsorized [`ii', 6] = `df_r'
 13.         matrix res_winsorized [`ii', 7] = `K'
 14.         matrix res_winsorized [`ii', 8] = e(widstat)
 15. }       

. 
. * Estimate with JK shocks as IV
. matrix res_JK_shocks = J(`L', 8, .)

. matrix colnames res_JK_shocks = lag IRF se lb ub df_resid K F_stat

.         
. forvalues ii = 1/`L' {
  2.         local ii_1 = `ii' - 1
  3.         quietly ivreghdfe f`ii_1'.Efor_Step2 l1.JK_shock l2.JK_shock l3.JK_shock l4.JK_shock /// 
>                 (SPFfor_Step2 = JK_shock), /// 
>                 absorb(ID) cluster(ID qtr)
  4.                 
.         * Collect the results and calculate 
.         * confidence intervals at the given significance level
.         local se = _se[SPFfor_Step2]
  5.         local df_r = e(df_r) 
  6.         local t_crit = invt(`df_r', `alpha' / 2)
  7.         
.         matrix res_JK_shocks [`ii', 1] = `ii'
  8.         matrix res_JK_shocks [`ii', 2] = _b[SPFfor_Step2]
  9.         matrix res_JK_shocks [`ii', 3] = `se'
 10.         matrix res_JK_shocks [`ii', 4] = _b[SPFfor_Step2] + ///
>                 `t_crit' * `se'
 11.         matrix res_JK_shocks [`ii', 5] = _b[SPFfor_Step2] - ///
>                 `t_crit' * `se'
 12.         matrix res_JK_shocks [`ii', 6] = `df_r'
 13.         matrix res_JK_shocks [`ii', 7] = `K'
 14.         matrix res_JK_shocks [`ii', 8] = e(widstat)
 15. }
Warning: estimated covariance matrix of moment conditions not of full rank.
         overidentification statistic not reported, and standard errors and
         model tests should be interpreted with caution.
Possible causes:
         number of clusters insufficient to calculate robust covariance matrix
         singleton dummy variable (dummy with one 1 and N-1 0s or vice versa)
partial option may address problem.

. 
. ******************
. *** Get graphs ***
. ******************
. 
. * Clean up
. shell rm -r `output_folder'

rm: ./output/idiosyncratic: No such file or directory

. shell mkdir -p ./output


. shell mkdir `output_folder'


. 
. * Get plots
. plot_IRF "res_baseline" `output_folder' "res_baseline"
file /Users/fpeters/Dropbox/KP/REStat/accept/submission_files/measuring_expectations/code/stata/output/idiosyncratic/res_baseline.pdf saved as PDF
    format

. plot_IRF "res_JK_shocks" `output_folder' "res_JK_shocks"
file /Users/fpeters/Dropbox/KP/REStat/accept/submission_files/measuring_expectations/code/stata/output/idiosyncratic/res_JK_shocks.pdf saved as
    PDF format

. 
. * Save estimated IRFs
. mat2txt, matrix(res_baseline) saving(`output_folder'/IRF_idiosyncratic.txt)

. mat2txt, matrix(res_winsorized) saving(`output_folder'/IRF_idiosyncratic_winsorized.txt)

. mat2txt, matrix(res_JK_shocks) saving(`output_folder'/IRF_idiosyncratic_JK_shocks.txt)

. mat2txt, matrix(AR_coefs) saving(`output_folder'/AR_coefs_dev_consensus.txt)

. mat2txt, matrix(AR_coefs_cov) saving(`output_folder'/AR_coefs_cov_dev_consensus.txt)

. 
end of do-file

. do aggregate_RR_shocks.do

. clear

. discard

. set more off

. 
. adopath ++ "./ado/"
  [1]              "./ado/"
  [2]              "../ssc/"
  [3]              "../tools/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. adopath ++ "../tools/"
  [1]              "../tools/"
  [2]              "./ado/"
  [3]              "../ssc/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. adopath ++ "../ssc/"
  [1]              "../ssc/"
  [2]              "../tools/"
  [3]              "./ado/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. 
. ******************
. *** Parameters ***
. ******************
. 
. local file_name "./input/consensus_dataset.csv"  // Data file

. local output_folder "./output/aggregate_RR_shocks" // Output directory

. local K = 4 // Number of lags to include when calculating local projections

. local L = 20 // Number of IRF coefficients to estimate

. local alpha = 0.05 // Significance level

. local L_NW = 5 // Number of lags for calculating Newey-West standard errors

. 
. *************************************
. *** Import data and set data type ***
. *************************************
. 
. import delimited using `file_name', case(preserve)
(encoding automatically selected: ISO-8859-1)
(10 vars, 215 obs)

. rename DATE Date

. 
. gen qtr = quarterly(Date,"YQ")

. format qtr %tq

. tsset qtr // Set to time series

Time variable: qtr, 1968q4 to 2022q2
        Delta: 1 quarter

. 
. ********************************
. *** Generate forecast errors ***
. ********************************
. 
. gen Efor_Step2 = Realiz1 - SPFfor_Step2
(5 missing values generated)

. 
. ***********************************
. *** Calculate local projections ***
. ***********************************
. 
. estimate_IRF_external_IV Realiz1 FFR RR_shocks , k(`K') l(`L')

. matrix IRF_actual_RR_shocks = e(s)

. 
. estimate_IRF_external_IV Efor_Step2 FFR RR_shocks , k(`K') l(`L')

. matrix IRF_1Q_ahead_RR_shocks = e(s)

. 
. ******************
. *** Get graphs ***
. ******************
. 
. * Clean up
. shell rm -r `output_folder'

rm: ./output/aggregate_RR_shocks: No such file or directory

. shell mkdir -p ./output


. shell mkdir `output_folder'


. 
. * Get plots
. plot_IRF "IRF_actual_RR_shocks" `output_folder' "IRF_actual_RR_shocks"
file
    /Users/fpeters/Dropbox/KP/REStat/accept/submission_files/measuring_expectations/code/stata/output/aggregate_RR_shocks/IRF_actual_RR_shocks.pdf
    saved as PDF format

. plot_IRF "IRF_1Q_ahead_RR_shocks" `output_folder' "IRF_1Q_ahead_RR_shocks"
file
    /Users/fpeters/Dropbox/KP/REStat/accept/submission_files/measuring_expectations/code/stata/output/aggregate_RR_shocks/IRF_1Q_ahead_RR_shocks.p
    > df saved as PDF format

. 
. * Save estimated IRFs
. mat2txt, matrix(IRF_actual_RR_shocks) saving(`output_folder'/IRF_actual_RR_shocks.txt)

. mat2txt, matrix(IRF_1Q_ahead_RR_shocks) saving(`output_folder'/IRF_1Q_ahead_RR_shocks.txt)

. 
end of do-file

. do CG_regressions.do

. clear

. discard

. set more off

. 
. adopath ++ "./ado/"
  [1]              "./ado/"
  [2]              "../ssc/"
  [3]              "../tools/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. 
. ******************
. *** Parameters ***
. ******************
. 
. local file_name_consensus "./input/consensus_dataset.csv"  // Data file

. local file_name_individual "./input/individual_dataset.csv" // Data file

. local output_folder "./output/CG_regressions" // Output directory

. local K = 4 // Number of lags to include when calculating local projections

. local L = 16 // Number of IRF coefficients to estimate

. local alpha = 0.05 // Significance level

. local L_NW = 5 // Number of lags for calculating Newey-West standard errors

. 
. *****************************
. *** Import CONSENSUS data ***
. *****************************
. 
. import delimited using `file_name_consensus', case(preserve)
(encoding automatically selected: ISO-8859-1)
(10 vars, 215 obs)

. rename DATE Date

. 
. gen qtr = quarterly(Date,"YQ")

. format qtr %tq

. tsset qtr // Set to time series

Time variable: qtr, 1968q4 to 2022q2
        Delta: 1 quarter

. 
. **************************
. *** Generate variables ***
. **************************
. 
. gen Efor_Step2 = Realiz1 - SPFfor_Step2
(5 missing values generated)

. gen Rfor_Step2 = SPFfor_Step2 - SPFfor_Step3
(5 missing values generated)

. 
. *******************
. *** Regressions ***
. *******************
. 
. * Clean up
. shell rm -r `output_folder'

rm: ./output/CG_regressions: No such file or directory

. shell mkdir -p ./output


. shell mkdir `output_folder'


. 
. * Regressions
. newey Efor_Step2 Rfor_Step2, lag(`K')

Regression with Newey–West standard errors      Number of obs     =        209
Maximum lag = 4                                 F(  1,       207) =       1.03
                                                Prob > F          =     0.3115

------------------------------------------------------------------------------
             |             Newey–West
  Efor_Step2 | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
  Rfor_Step2 |    .402739   .3969709     1.01   0.312    -.3798853    1.185363
       _cons |  -.0241376   .1402743    -0.17   0.864     -.300687    .2524118
------------------------------------------------------------------------------

. matrix CG_coefs_cons = e(b)

. matrix CG_cov_cons = e(V)

. 
. * Save output
. mat2txt, matrix(CG_coefs_cons) saving(`output_folder'/CG_coefs_consensus.txt)

. mat2txt, matrix(CG_cov_cons) saving(`output_folder'/CG_cov_consensus.txt)

. 
. clear

. 
. ******************************
. *** Import INDIVIDUAL data ***
. ******************************
. 
. import delimited using `file_name_individual', case(preserve)
(encoding automatically selected: ISO-8859-1)
(10 vars, 71,810 obs)

. 
. gen qtr = quarterly(DATE,"YQ")

. format qtr %tq

. xtset ID qtr // Set to panel data

Panel variable: ID (strongly balanced)
 Time variable: qtr, 1968q4 to 2022q2
         Delta: 1 quarter

. 
. **************************
. *** Generate variables ***
. **************************
. 
. gen Efor_Step2 = Realiz1 - SPFfor_Step2
(63,826 missing values generated)

. gen Rfor_Step2 = SPFfor_Step2 - SPFfor_Step3
(65,720 missing values generated)

. 
. *******************
. *** Regressions ***
. *******************
. 
. reghdfe Efor_Step2 Rfor_Step2, noabsorb vce(cluster ID DATE)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      6,057
Absorbing 1 HDFE group                            F(   1,    208) =      41.41
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.0705
                                                  Adj R-squared   =     0.0703
Number of clusters (ID)      =        285         Within R-sq.    =     0.0705
Number of clusters (DATE)    =        209         Root MSE        =     1.7847

                              (Std. err. adjusted for 209 clusters in ID DATE)
------------------------------------------------------------------------------
             |               Robust
  Efor_Step2 | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
  Rfor_Step2 |  -.3496652   .0543367    -6.44   0.000    -.4567865   -.2425439
       _cons |   .0058139   .1188775     0.05   0.961    -.2285452    .2401731
------------------------------------------------------------------------------

. matrix CG_coefs_micro_no_FE = e(b)

. matrix CG_cov_micro_no_FE = e(V)

. 
. reghdfe Efor_Step2 Rfor_Step2, absorb(ID) vce(cluster ID DATE)
(dropped 27 singleton observations)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      6,030
Absorbing 1 HDFE group                            F(   1,    208) =      79.79
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.2131
                                                  Adj R-squared   =     0.1780
Number of clusters (ID)      =        258         Within R-sq.    =     0.0911
Number of clusters (DATE)    =        209         Root MSE        =     1.6778

                              (Std. err. adjusted for 209 clusters in ID DATE)
------------------------------------------------------------------------------
             |               Robust
  Efor_Step2 | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
  Rfor_Step2 |  -.3814679   .0427056    -8.93   0.000    -.4656592   -.2972766
       _cons |   .0042816   .0975459     0.04   0.965    -.1880237    .1965869
------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
          ID |       258         258           0    *|
-----------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. matrix CG_coefs_micro_FE = e(b)

. matrix CG_cov_micro_FE = e(V)

. 
. reghdfe Efor_Step2 Rfor_Step2, absorb(DATE) vce(cluster ID DATE)
(MWFE estimator converged in 1 iterations)

HDFE Linear regression                            Number of obs   =      6,057
Absorbing 1 HDFE group                            F(   1,    208) =     220.72
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.7358
                                                  Adj R-squared   =     0.7264
Number of clusters (ID)      =        285         Within R-sq.    =     0.3180
Number of clusters (DATE)    =        209         Root MSE        =     0.9683

                              (Std. err. adjusted for 209 clusters in ID DATE)
------------------------------------------------------------------------------
             |               Robust
  Efor_Step2 | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
  Rfor_Step2 |  -.4927499   .0331671   -14.86   0.000    -.5581368   -.4273631
       _cons |   .0068397   .0257369     0.27   0.791    -.0438989    .0575782
------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
        DATE |       209         209           0    *|
-----------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. matrix CG_coefs_idio_no_FE = e(b)

. matrix CG_cov_idio_no_FE = e(V)

. 
. reghdfe Efor_Step2 Rfor_Step2, absorb(DATE ID) vce(cluster ID DATE)
(dropped 27 singleton observations)
(MWFE estimator converged in 13 iterations)
Warning: VCV matrix was non-positive semi-definite; adjustment from Cameron, Gelbach & Miller applied.

HDFE Linear regression                            Number of obs   =      6,030
Absorbing 2 HDFE groups                           F(   1,    208) =     296.31
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.7886
                                                  Adj R-squared   =     0.7708
Number of clusters (ID)      =        258         Within R-sq.    =     0.3509
Number of clusters (DATE)    =        209         Root MSE        =     0.8859

                              (Std. err. adjusted for 209 clusters in ID DATE)
------------------------------------------------------------------------------
             |               Robust
  Efor_Step2 | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
  Rfor_Step2 |  -.4867937   .0282793   -17.21   0.000    -.5425445    -.431043
       _cons |   .0049959   .0009809     5.09   0.000     .0030622    .0069295
------------------------------------------------------------------------------

Absorbed degrees of freedom:
-----------------------------------------------------+
 Absorbed FE | Categories  - Redundant  = Num. Coefs |
-------------+---------------------------------------|
        DATE |       209         209           0    *|
          ID |       258         258           0    *|
-----------------------------------------------------+
* = FE nested within cluster; treated as redundant for DoF computation

. matrix CG_coefs_idio_FE = e(b)

. matrix CG_cov_idio_FE = e(V)

. 
. * Save output
. mat2txt, matrix(CG_coefs_micro_no_FE) saving(`output_folder'/CG_coefs_micro_no_FE.txt)

. mat2txt, matrix(CG_cov_micro_no_FE) saving(`output_folder'/CG_cov_micro_no_FE.txt)

. 
. mat2txt, matrix(CG_coefs_micro_FE) saving(`output_folder'/CG_coefs_micro_FE.txt)

. mat2txt, matrix(CG_cov_micro_FE) saving(`output_folder'/CG_cov_micro_FE.txt)

. 
. mat2txt, matrix(CG_coefs_idio_no_FE) saving(`output_folder'/CG_coefs_idio_no_FE.txt)

. mat2txt, matrix(CG_cov_idio_no_FE) saving(`output_folder'/CG_cov_idio_no_FE.txt)

. 
. mat2txt, matrix(CG_coefs_idio_FE) saving(`output_folder'/CG_coefs_idio_FE.txt)

. mat2txt, matrix(CG_cov_idio_FE) saving(`output_folder'/CG_cov_idio_FE.txt)

. 
. 
end of do-file

. do horizons.do

. clear

. discard

. set more off

. 
. adopath ++ "./ado/"
  [1]              "./ado/"
  [2]              "../ssc/"
  [3]              "../tools/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. 
. ******************
. *** Parameters ***
. ******************
. 
. local file_name "./input/consensus_dataset.csv"  // Data file

. local output_folder "./output/horizons" // Output directory

. local K = 4 // Number of lags to include when calculating local projections

. local L = 16 // Number of IRF coefficients to estimate

. local alpha = 0.05 // Significance level

. local L_NW = 5 // Number of lags for calculating Newey-West standard errors

. 
. *************************************
. *** Import data and set data type ***
. *************************************
. 
. import delimited using `file_name', case(preserve)
(encoding automatically selected: ISO-8859-1)
(10 vars, 215 obs)

. rename DATE Date

. 
. gen qtr = quarterly(Date,"YQ")

. format qtr %tq

. tsset qtr // Set to time series

Time variable: qtr, 1968q4 to 2022q2
        Delta: 1 quarter

. 
. ********************************
. *** Generate forecast errors ***
. ********************************
. 
. gen Efor_Step2 = Realiz1 - SPFfor_Step2
(5 missing values generated)

. gen Efor_Step3 = Realiz1 - SPFfor_Step3
(6 missing values generated)

. gen Efor_Step4 = Realiz1 - SPFfor_Step4
(7 missing values generated)

. 
. * There is a missing forecast for Q4-ahead forecast
. * in 1975:Q3, replace with value for Q3-ahead forecast
. replace SPFfor_Step5 = SPFfor_Step4 if SPFfor_Step5 == . & Date == "1975:03"
(1 real change made)

. 
. gen Efor_Step5 = Realiz1 - SPFfor_Step5
(12 missing values generated)

. 
. ****************************************
. *** Set same sample for all horizons ***
. ****************************************
. 
. drop if qtr <= tq(1971q1)
(10 observations deleted)

. 
. ***********************************
. *** Calculate local projections ***
. ***********************************
. 
. estimate_IRF_LP Efor_Step2, k(`K') l(`L') alpha(`alpha') min_lags_NW(`L_NW') 

. matrix IRF_LP_1Q_ahead = e(s)

. 
. estimate_IRF_LP Efor_Step3, k(`K') l(`L') alpha(`alpha') min_lags_NW(`L_NW') 

. matrix IRF_LP_2Q_ahead = e(s)

. 
. estimate_IRF_LP Efor_Step4, k(`K') l(`L') alpha(`alpha') min_lags_NW(`L_NW') 

. matrix IRF_LP_3Q_ahead = e(s)

. 
. estimate_IRF_LP Efor_Step5, k(`K') l(`L') alpha(`alpha') min_lags_NW(`L_NW') 

. matrix IRF_LP_4Q_ahead = e(s)

. 
. * Clean up
. shell rm -r `output_folder'

rm: ./output/horizons: No such file or directory

. shell mkdir -p ./output


. shell mkdir `output_folder'


. 
. * Save estimated IRFs
. mat2txt, matrix(IRF_LP_1Q_ahead) saving(`output_folder'/IRF_LP_1Q_ahead.txt)

. mat2txt, matrix(IRF_LP_2Q_ahead) saving(`output_folder'/IRF_LP_2Q_ahead.txt)

. mat2txt, matrix(IRF_LP_3Q_ahead) saving(`output_folder'/IRF_LP_3Q_ahead.txt)

. mat2txt, matrix(IRF_LP_4Q_ahead) saving(`output_folder'/IRF_LP_4Q_ahead.txt)

. 
end of do-file

. do rolling.do

. clear

. discard

. set more off

. 
. adopath ++ "./ado/"
  [1]              "./ado/"
  [2]              "../ssc/"
  [3]              "../tools/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. adopath ++ "../tools/"
  [1]              "../tools/"
  [2]              "./ado/"
  [3]              "../ssc/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. adopath ++ "../ssc/"
  [1]              "../ssc/"
  [2]              "../tools/"
  [3]              "./ado/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. 
. ******************
. *** Parameters ***
. ******************
. 
. local file_name "./input/consensus_dataset.csv"  // Data file

. local output_folder "./output/rolling" // Output directory

. local L_NW = 5 // Number of lags for calculating Newey-West standard errors

. 
. *************************************
. *** Import data and set data type ***
. *************************************
. 
. import delimited using `file_name', case(preserve)
(encoding automatically selected: ISO-8859-1)
(10 vars, 215 obs)

. rename DATE Date

. 
. gen qtr = quarterly(Date,"YQ")

. format qtr %tq

. tsset qtr // Set to time series

Time variable: qtr, 1968q4 to 2022q2
        Delta: 1 quarter

. 
. ********************************
. *** Generate forecast errors ***
. ********************************
. 
. * Clean up
. shell rm -r `output_folder'

rm: ./output/rolling: No such file or directory

. shell mkdir -p ./output


. shell mkdir `output_folder'


. 
. * Generate variables
. gen Efor_Step2 = Realiz1 - SPFfor_Step2
(5 missing values generated)

. forvalues k = 1/4 {
  2.         quietly gen l`k'_Efor_Step2 = l`k'.Efor_Step2
  3.         quietly gen l`k'_Realiz1 = l`k'.Realiz1
  4. }

. 
. ******************
. *** Estimation ***
. ******************
. 
. * Rolling regressions
. rolling _b _se e(N) e(df_r), window(32) saving(IRF_LP_1Q_ahead, replace) keep(Date) reject(e(N) < 32): ///
>         newey f0.Efor_Step2 l1_Efor_Step2 l2_Efor_Step2 l3_Efor_Step2 l4_Efor_Step2, lag(`L_NW')
(running newey on estimation sample)
(file IRF_LP_1Q_ahead.dta not found)

Rolling replications (184)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
xxxxx.............................................    50
..................................................   100
..................................................   150
..............................xxxx
file IRF_LP_1Q_ahead.dta saved

. rolling _b _se e(N) e(df_r), window(32) saving(IRF_actual, replace) keep(Date) reject(e(N) < 32): ///
>         newey f0.Realiz1 l1_Realiz1 l2_Realiz1 l3_Realiz1 l4_Realiz1, lag(`L_NW')
(running newey on estimation sample)
(file IRF_actual.dta not found)

Rolling replications (184)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
xxxx..............................................    50
..................................................   100
..................................................   150
..............................xxxx
file IRF_actual.dta saved

. 
. * Save results
. clear

. use IRF_LP_1Q_ahead.dta
(rolling: newey)

. rename _b_l1_Efor_Step2 IRF

. rename _se_l1_Efor_Step2 se

. rename _eq2_stat_2 df_resid

. export delimited date IRF se df_resid using `output_folder'/rolling_IRF_1Q_ahead.csv
file ./output/rolling/rolling_IRF_1Q_ahead.csv saved

. 
. clear

. use IRF_actual.dta
(rolling: newey)

. rename _b_l1_Realiz1 IRF

. rename _se_l1_Realiz1 se

. rename _eq2_stat_2 df_resid

. export delimited date IRF se df_resid using `output_folder'/rolling_IRF_actual.csv
file ./output/rolling/rolling_IRF_actual.csv saved

. 
. clear

. shell rm ./IRF_LP_1Q_ahead.dta


. shell rm ./IRF_actual.dta


. 
end of do-file

. do state_dependence.do

. clear

. discard

. set more off

. 
. adopath ++ "./ado/"
  [1]              "./ado/"
  [2]              "../ssc/"
  [3]              "../tools/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. adopath ++ "../tools/"
  [1]              "../tools/"
  [2]              "./ado/"
  [3]              "../ssc/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. adopath ++ "../ssc/"
  [1]              "../ssc/"
  [2]              "../tools/"
  [3]              "./ado/"
  [4]  (BASE)      "/Applications/Stata/ado/base/"
  [5]  (SITE)      "/Applications/Stata/ado/site/"
  [6]              "."
  [7]  (PERSONAL)  "/Users/fpeters/Documents/Stata/ado/personal/"
  [8]  (PLUS)      "/Users/fpeters/Library/Application Support/Stata/ado/plus/"
  [9]  (OLDPLACE)  "~/ado/"

. 
. ******************
. *** Parameters ***
. ******************
. 
. local file_name "./input/consensus_dataset.csv"  // Data file

. local output_folder "./output/state_dependence" // Output directory

. local K = 4 // Number of lags to include when calculating local projections

. local L = 4 // Number of IRF coefficients to estimate

. local alpha = 0.05 // Significance level

. local L_NW = 5 // Number of lags for calculating Newey-West standard errors

. 
. *************************************
. *** Import data and set data type ***
. *************************************
. 
. import delimited using `file_name', case(preserve)
(encoding automatically selected: ISO-8859-1)
(10 vars, 215 obs)

. rename DATE Date

. 
. gen qtr = quarterly(Date,"YQ")

. format qtr %tq

. tsset qtr // Set to time series

Time variable: qtr, 1968q4 to 2022q2
        Delta: 1 quarter

. 
. ********************************
. *** Generate forecast errors ***
. ********************************
. 
. gen Efor_Step2 = Realiz1 - SPFfor_Step2
(5 missing values generated)

. 
. *******************************************
. *** Generate dummy variables for states ***
. *******************************************
. 
. quietly summarize Realiz1, detail

. scalar infl_p75 = r(p75)

. 
. gen abs_Efor_Step2 = abs(Efor_Step2)
(5 missing values generated)

. quietly summarize abs_Efor_Step2, detail

. scalar abs_fe_p75 = r(p75)

. 
. gen high_inflation = 0

. replace high_inflation = 1 if Realiz1 >= infl_p75
(57 real changes made)

. replace high_inflation = . if missing(Realiz1)
(4 real changes made, 4 to missing)

. 
. gen large_fe  = 0

. replace large_fe = 1 if abs_Efor_Step2 >= abs_fe_p75
(58 real changes made)

. replace large_fe = . if missing(abs_Efor_Step2)
(5 real changes made, 5 to missing)

. 
. gen great_moderation = 0

. replace great_moderation = 1 if qtr >= quarterly("1985:01", "YQ") & ///
>         qtr < quarterly("2007:01", "YQ")
(88 real changes made)

. replace great_moderation = . if missing(qtr)
(0 real changes made)

. 
. ****************************
. *** Estimate regressions ***
. ****************************
. 
. * For actual inflation
. estimate_IRF_LP Realiz1, k(`K') l(`L') alpha(`alpha') min_lags_NW(`L_NW') 

. matrix IRF_actual_baseline = e(s)

. 
. estimate_IRF_LP_state_dep Realiz1 high_inflation , k(`K') l(`L') min_lags_NW(`L_NW')

. matrix IRF_actual_high_inflation = e(s)

. 
. estimate_IRF_LP_state_dep Realiz1 NBER_recession , k(`K') l(`L') min_lags_NW(`L_NW')

. matrix IRF_actual_NBER_recession = e(s)

. 
. estimate_IRF_LP_state_dep Realiz1 great_moderation , k(`K') l(`L') min_lags_NW(`L_NW')

. matrix IRF_actual_great_moderation = e(s)

. 
. estimate_IRF_LP_state_dep Realiz1 large_fe , k(`K') l(`L') min_lags_NW(`L_NW')

. matrix IRF_actual_large_fe = e(s) 

. 
. * For forecast errors
. estimate_IRF_LP Efor_Step2, k(`K') l(`L') alpha(`alpha') min_lags_NW(`L_NW') 

. matrix IRF_baseline = e(s)

. 
. estimate_IRF_LP_state_dep Efor_Step2 high_inflation , k(`K') l(`L') min_lags_NW(`L_NW')

. matrix IRF_high_inflation = e(s)

. 
. estimate_IRF_LP_state_dep Efor_Step2 NBER_recession , k(`K') l(`L') min_lags_NW(`L_NW')

. matrix IRF_NBER_recession = e(s)

. 
. estimate_IRF_LP_state_dep Efor_Step2 great_moderation , k(`K') l(`L') min_lags_NW(`L_NW')

. matrix IRF_great_moderation = e(s)

. 
. estimate_IRF_LP_state_dep Efor_Step2 large_fe , k(`K') l(`L') min_lags_NW(`L_NW')

. matrix IRF_large_fe = e(s)

. 
. * Clean up
. shell rm -r `output_folder'

rm: ./output/state_dependence: No such file or directory

. shell mkdir -p ./output


. shell mkdir `output_folder'


. 
. * Save estimated IRFs
. mat2txt, matrix(IRF_actual_baseline) saving(`output_folder'/IRF_actual_baseline.txt)

. mat2txt, matrix(IRF_actual_high_inflation) saving(`output_folder'/IRF_actual_high_inflation.txt)

. mat2txt, matrix(IRF_actual_NBER_recession) saving(`output_folder'/IRF_actual_NBER_recession.txt)

. mat2txt, matrix(IRF_actual_great_moderation) saving(`output_folder'/IRF_actual_great_moderation.txt)

. mat2txt, matrix(IRF_actual_large_fe) saving(`output_folder'/IRF_actual_large_fe.txt)

. 
. mat2txt, matrix(IRF_baseline) saving(`output_folder'/IRF_baseline.txt)

. mat2txt, matrix(IRF_high_inflation) saving(`output_folder'/IRF_high_inflation.txt)

. mat2txt, matrix(IRF_NBER_recession) saving(`output_folder'/IRF_NBER_recession.txt)

. mat2txt, matrix(IRF_great_moderation) saving(`output_folder'/IRF_great_moderation.txt)

. mat2txt, matrix(IRF_large_fe) saving(`output_folder'/IRF_large_fe.txt)

. 
end of do-file

. 
end of do-file
